import vnode from './vnode';

export function h(
    sel,
    data,
    children
) {
    if (children === undefined) {
        new Error("抛出异常")
    }
    if (typeof children === 'string' || typeof children === 'number') {
       return vnode(sel, data, undefined, children, undefined);
    } else if (Array.isArray(children)) {
        var childList = [];
        children.forEach(child => {
            if (Object.prototype.toString.call(child) === '[object Object]' 
                && child.hasOwnProperty("sel")) {
                childList.push(child);
            }
        })
       return vnode(sel, data, childList)
    } else if(Object.prototype.toString.call(children) === '[object Object]') {
       return vnode(sel, data, [children], undefined, undefined);
    } else {
        new Error("invalid param");
    }
}